<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>es6-proxy</title>
  </head>
  <body>
    <script>
      const promise1 = Promise.resolve(3);
      const promise2 = 42;
      const promise3 = new Promise((resolve, reject) => {
        setTimeout(resolve, 100, "foo");
      });

      Promise.all([promise1, promise2, promise3]).then((values) => {
        console.log(values);
      });

      function fn() {
        return new Promise((resolve, reject) => {
          let randomNum = parseInt(Math.random() * 6 + 1);
          console.log(randomNum);
          if (randomNum > 3) {
            resolve("买");
          } else {
            reject("不买");
          }
        });
      }

      Promise.all([fn(), promise3])
        .then((values) => {
          console.log(values);
        })
        .catch((err) => {
          console.log(err, "err");
        });

      // async function test() {
      //   try {
      //     let res = await Promise.all([fn(), fn()]);
      //     console.log(res, "success");
      //   } catch (error) {
      //     console.log(error, "error");
      //   }
      // }

      function test() {
        Promise.all([fn(), fn()])
          .then((res) => {
            console.log(res, "success");
          })
          .catch((error) => {
            console.log(error, "error");
          });
      }

      test();
    </script>
  </body>
</html>
